#include "InetTcp.h"
#include "PcapExceptions.h"


namespace Pacap {



PackType InetTcp::pack()
{
    throw ExceptUndefineMethod("not defined method");
}

void InetTcp::unpack(PackType hexData)
{
    if( hexData.length() < sizeof(struct head) ){
        throw ExceptUncorrectLength("can not allow length of hexData less then pack");
    }
    ::memcpy(&(this->head),hexData.data(),sizeof(struct head));
    uint32_t headLen = getDoff();

    data.assign(hexData.data()+headLen,hexData.length()-headLen);
}

u_int16_t InetTcp::getSource() const
{
    return head.source;
}

void InetTcp::setSource(const u_int16_t &value)
{
    head.source = value;
}

u_int16_t InetTcp::getDest() const
{
    return head.dest;
}

void InetTcp::setDest(const u_int16_t &value)
{
    head.dest = value;
}

u_int32_t InetTcp::getSeq() const
{
    return head.seq;
}

void InetTcp::setSeq(const u_int32_t &value)
{
    head.seq = value;
}

u_int32_t InetTcp::getAckSeq() const
{
    return head.ackSeq;
}

void InetTcp::setAckSeq(const u_int32_t &value)
{
    head.ackSeq = value;
}

u_int16_t InetTcp::getRes1() const
{
    return head.res1;
}

void InetTcp::setRes1(const u_int16_t &value)
{
    head.res1 = value;
}

u_int16_t InetTcp::getDoff() const
{
    return head.doff*4;
}

void InetTcp::setDoff(const u_int16_t &value)
{
    head.doff = value;
}

PackType InetTcp::getData() const
{
    return data;
}

void InetTcp::setData(const PackType &value)
{
    data = value;
}

size_t InetTcp::getLENGTH()
{
    return sizeof(struct head);
}



}
